/**
 * @Author 韦建韩
 * @Date 2022/7/20
 */
package com.example.blog.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class UserControllerAop {
    @Pointcut("execution(* com.example.blog.web.userController.UserBlogController.*(..))")
    public void pointCut(){
    };
    @Before("pointCut()")
    public void check() {
        ServletRequestAttributes attributes =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String url = request.getRequestURL().toString();
        String ip = request.getRemoteAddr();
        System.out.println(url);
        System.out.println(ip);
    }
}
